﻿using System.Collections.Generic;
using System.Linq;
using Peninsula.DataAccess.POCO;
using Peninsula.Site.Data.Helper;
using Peninsula.Site.Data.Models;

namespace Peninsula.Web.Models.Sessions
{

    public class AdminSession
    {
        public AdminSession(Admin admin, IEnumerable<Permission> permission)
        {
            AdminEntity = admin;

            //缓存所有角色/权限
            AllRoles = admin.Roles.ToList();
            admin.Roles = AllRoles;
            AllPermissions = permission.ToList();
            MenuItems = MenuHelper.BuildAdminMenu(AllPermissions);
        }

        /// <summary>
        /// 账户id
        /// </summary>
        public string Identity
        {
            get
            {
                return AdminEntity.Id;
            }
        }

        public string AdminUserName
        {
            get
            {
                return AdminEntity.UserName;
            }
        }

        /// <summary>
        /// 拥有所有权限
        /// </summary>
        public bool IsSuperAdmin
        {
            get { return AdminEntity.IsSuperAdmin; }
        }

        public Admin AdminEntity { get; private set; }

        public List<Role> AllRoles { get; private set; }

        public List<Permission> AllPermissions { get; private set; }

        public List<MenuItem> MenuItems { get; set; }
    }
}